package io.github.enbool.repository;

import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import io.github.enbool.domain.User;


public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
	
	User findByUsername(String username);
	User findByUsernameOrPhone(String username, String phone);
	Page<User> findByOrganizationId(Long organizationId, Pageable pageable);
	
	@Modifying
	@Transactional
	@Query("UPDATE User u SET u.enabled = ?2 WHERE u.id = ?1")
	void enableUser(Long id, Boolean enabled);
}
